<!-- 搜索表单 -->
<template>
  <div>
    <div class="selectTime flex-align-center">
      <div class="orderStatus">订单状态:</div>
      <ul class="timeTab"
          v-for="(item, index) in orderStatusArr"
          :key="index">
        <li :class="[currentIndex == index ? 'active' : '']"
            @click="switchTimeTab(index,item.id)">{{ item.value }}</li>
      </ul>
    </div>
    <el-form label-width="100px"
             class="ele-form-search"
             ref="form"
             @keyup.enter.native="search"
             @submit.native.prevent>
      <el-row :gutter="15">

        <el-col :lg="6"
                :md="12">
          <el-form-item label="vip购买者:">
            <el-input clearable
                      v-model="where.nickname"
                      placeholder="请输入vip购买者" />

          </el-form-item>
        </el-col>
        <el-col :lg="6"
                :md="12">
          <el-form-item label="订单号:">
            <el-input clearable
                      v-model="where.order_sn"
                      placeholder="请输入订单号" />

          </el-form-item>
        </el-col>

        <el-col :lg="6"
                :md="12">
          <el-form-item label="有效期(天):">
            <el-input clearable
                      v-model="where.effective_time"
                      placeholder="请输入有效期(天)" />

          </el-form-item>
        </el-col>

        <el-col :lg="6"
                :md="12">
          <el-form-item label="创建时间:"
                        prop="dateRange">
            <el-date-picker v-model="where.dateRange"
                            type="datetimerange"
                            unlink-panels
                            range-separator="至"
                            start-placeholder="开始时间"
                            end-placeholder="结束时间"
                            :default-time="['00:00:00', '23:59:59']"
                            value-format="yyyy-MM-dd HH:mm:ss"
                            class="ele-fluid" />
          </el-form-item>
        </el-col>
        <el-col :lg="6"
                :md="12">
          <div class="ele-form-actions">
            <el-button type="primary"
                       icon="el-icon-search"
                       class="ele-btn-icon"
                       @click="search">
              查询
            </el-button>

            <el-button @click="reset('form')">重置</el-button>
          </div>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { orderStatusArr } from '../constant/constant';
const DEFAULT_WHERE = {
  nickname: '',
  dateRange: [],
  effective_time: '',
  order_sn: ''

};

export default {
  name: 'RoleSearch',
  data () {
    return {
      orderStatusArr,
      // 表单数据
      where: { ...DEFAULT_WHERE },
      currentIndex: 0,
      sumbitForm: {},
      id: 1



    };
  },
  methods: {
    switchTimeTab (index, id) {
      this.currentIndex = index;
      this.id = id
      this.$emit('search', { type: id });
    },
    /* 搜索 */
    search () {
      for (const key in this.where) {
        if (key == 'dateRange') {
          let startTime = this.where[key]?.[0];
          let endTime = this.where[key]?.[1];
          this.sumbitForm['start_time'] =
            startTime == undefined ? '' : startTime;
          this.sumbitForm['end_time'] =
            endTime == undefined ? '' : endTime;
        } else if (key == 'orderAmount') {
          this.sumbitForm['startOrderAmount'] =
            this.where[key].startOrderAmount == undefined
              ? ''
              : this.where[key].startOrderAmount;
          this.sumbitForm['endOrderAmount'] =
            this.where[key].endOrderAmount == undefined
              ? ''
              : this.where[key].endOrderAmount;
        } else {
          this.sumbitForm[key] = this.where[key];
        }
      }

      console.log(this.sumbitForm)
      this.$emit('search', { ...this.sumbitForm, type: this.id });
    },

    /*  重置 */
    reset (formName) {
      this.$refs[formName].resetFields();

      this.where = {}
      this.sumbitForm = {};
      this.currentIndex = 0
      this.id = 1
      this.$emit('search', this.sumbitForm);
    }
  }
};
</script>

<style lang="less" scoped>
// /deep/ .el-input__inner {
//   width: 342px !important;
// }
.selectTime {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  .timeTab {
    display: flex;
    align-items: center;
    margin-right: 20px;
    li {
      list-style-type: none;
      display: block;
      width: 110px;
      height: 38px;
      line-height: 38px;
      text-align: center;
      border: 1px solid #d9d9d9;
      border-radius: 10px;
    }
    .active {
      width: 110px;
      height: 38px;
      border-radius: 6px;
      background: #1890ff;
      color: #fff;
      text-align: center;
      line-height: 38px;
    }
  }
  .orderStatus {
    min-width: 77px;
    height: 34px;
    font-size: 14px;
    line-height: 34px;
  }
  .filterDate {
    text-align: center;
    line-height: 34px;
    width: 90px;
    height: 34px;
    font-size: 14px;
    border-radius: 2px 0px 0px 2px;
    border: 1px solid #d9d9d9;
    border-right: none;
  }
  .ele-fluid {
    width: 300px !important;
  }
}
.searchContainer {
  padding-bottom: 15px;
}
/deep/ .el-form-item__label {
  text-align: inherit;
}
.navList {
  margin-bottom: 25px;
  font-weight: 700;
}
</style>
